import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:qunaimedical/models/patient_record.dart';

/// 患者病例
class ItemPatientRecord extends StatelessWidget {
  final PatientRecord item;
  final GestureTapCallback onTap;
  final VoidCallback onDelete;

  const ItemPatientRecord({Key key, this.item, this.onTap, this.onDelete})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Slidable(
      actionPane: SlidableScrollActionPane(),
      actionExtentRatio: 0.2,
      secondaryActions: <Widget>[
        IconSlideAction(
          caption: '删除',
          color: Colors.red,
          icon: Icons.delete_forever,
          onTap: onDelete,
        ),
      ],
      child: InkWell(
        onTap: onTap,
        child: Container(
          color: Colors.white,
          height: 100,
          child: Row(
            children: [
              Container(
                margin: EdgeInsets.all(16),
                child: Image.asset(
                  'assets/images/ic_patient_case.png',
                  width: 50,
                  height: 50,
                ),
              ),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Text(
                      item.content,
                      style:
                          TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                    ),
                    SizedBox(height: 5),
                    Text(
                      item.history,
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                    ),
                    SizedBox(height: 5),
                    Text(
                      '咨询时间：${item.checkTime.substring(0, 16)}',
                      style: Theme.of(context).textTheme.caption,
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
